home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / SourceCode / OOP_Course / Examples / DrawTests / UserPath / UPView.m < prev    next >
Text File  |  1992-12-19  |  2KB  |  81 lines

  1.  
  2. /* Generated by Interface Builder */
  3.  
  4. #import "UPView.h"
  5.  
  6. @implementation UPView
  7.  
  8. - initFrame:(const NXRect *)theFrame
  9. {
  10.     [super initFrame:theFrame];
  11.     sqSide=100.;                              // and length of a side
  12.     NXSetRect(&sqRect,bounds.size.width/2.0,bounds.size.height/2.0,3*sqSide,sqSide);
  13.     backgroundGray=NX_WHITE;                // init the background gray level
  14.     userPath = newUserPath();                // create a user path 
  15.  
  16.     return self;
  17. }
  18.  
  19. - (float)backgroundGray
  20. {
  21.     return backgroundGray;
  22. }
  23.  
  24. - takeBackgroundGrayFrom:sender
  25. {
  26.     backgroundGray = [sender floatValue];    // read the background gray slider
  27.     [self display];
  28.     return self;
  29. }
  30.  
  31. - drawSelf:(const NXRect *)r :(int)c
  32. {
  33.      int    i, length = sqSide/8;
  34.      
  35.  /* Draw background */
  36.     PSsetgray(backgroundGray);
  37.     NXRectFill(&bounds);
  38.  /* Start Drawing */
  39.     PSsetgray(NX_BLACK);
  40.     PSsetlinewidth(5.0);
  41.  
  42.     beginUserPath(userPath, YES);        // start generating a stroke path with cache (boolean)
  43.  
  44.         UPmoveto(userPath, sqRect.origin.x, sqRect.origin.y);
  45.         for(i = 0; i<12; i++){
  46.             UPrlineto(userPath, length, 0.0);   // update bounding box at every step
  47.             UPrlineto(userPath,0.0, 8*length);
  48.             UPrlineto(userPath, length,0.0);
  49.             UPrlineto(userPath,0.0,-8*length);
  50.         }
  51.  
  52.     endUserPath(userPath, dps_ustroke);    // specify the stroke type
  53.     sendUserPath(userPath);                // send the path to server
  54.     
  55.     return self;
  56. }
  57.  
  58. - mouseDownAction:(NXPoint *)currentLocation
  59. {    
  60.     [self mouseDraggedAction:currentLocation];  //now do same as when dragging
  61.     return self;
  62. }
  63.  
  64. - mouseDraggedAction:(NXPoint *)currentLocation
  65. {
  66.     xOffset = sqRect.size.width/2;    // set the offsets for movement wrt the center
  67.     yOffset = sqRect.size.height/2;    // of drawing
  68.     sqRect.origin.x  = currentLocation->x - xOffset; // new x and y locations are center
  69.     sqRect.origin.y  = currentLocation->y - yOffset; // of drawing
  70.     [self display];
  71.     return self;
  72. }
  73.  
  74. - free
  75. {
  76.     freeUserPath(userPath);
  77.     return [super free];
  78.  }
  79.  
  80. @end
  81.